package com.zjuee.web.ledger.controller;

import com.zjuee.base.bean.response.R;
import com.zjuee.base.constant.Common;
import com.zjuee.service.LedgerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author wu liang
 * @since 1.0
 */
@Slf4j
@RestController
@RequestMapping(Common.Service.ZJUEE_CO_MAIN_LEDGER_URL_PREFIX)
public class ControllerLedger {

    @Resource
    private LedgerService ledgerService;

    //查询是否存在库存为-1的数据
    @GetMapping("/count")
    public R<Boolean> selectByGather(Long planId) {
        try {
//            LoginDto loginDto = (LoginDto) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            Boolean select = ledgerService.selectByGather(planId);
            if (null != select) {
                return R.ok(select);
            }
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
        return R.fail("Resource does not exist");
    }
}
